EUI.ScanTestView = EUI.extend(EUI.CustomUI, {
    renderTo: "",
    currentDocCateId: MyUtils.uuid.newUuid(),
    websocket: null,
    initComponent: function () {
        var g = this;
        EUI.Container({
            renderTo: this.renderTo,
            // layout: "border",
            border: false,
            //padding: 8,
            itemspace: 10,
            items: [{
                xtype: "Button",
                title: "扫描",
                handler: function () {
                    if ('WebSocket' in window) {
                        websocket = new WebSocket("ws://localhost:9010/websocket/socketServer");
                    }
                    else if ('MozWebSocket' in window) {
                        websocket = new MozWebSocket("ws://localhost:9010/websocket/socketServer");
                    }
                    else {
                        websocket = new SockJS("http://localhost:9010/sockjs/socketServer");
                    }
                    websocket.onopen = function(openEvt) {
                        //alert(openEvt.Data);
                    };
                    websocket.onerror = function() {};
                    websocket.onclose = function() {
                        websocket = null;
                    };
                    websocket.onmessage = function(evt) {
                        g.setScanFiles(evt.data);
                    };
               /*     function doSend() {
                        var msg = document.getElementById("inputMsg").value;
                        websocket.send(msg);//调用后台handleTextMessage方法
                    }*/
                    window.close = function() {
                        websocket.onclose();
                        websocket = null;
                    }

                    //通过signalR与后台通信，扫描完毕时刷新缩略图
                    // Reference the auto-generated proxy for the hub.
                    /*
                    var scanHub = $.connection.scanHub;
                    scanHub.client.scanComplete = function(fileInfos) {
                        //断开连接
                        $.connection.hub.stop();
                        if (fileInfos) {
                            // g.setScanFiles(fileInfos);
                        }
                    }
                    $.connection.hub.error(function(error) {
                        console.log('SignalR error: ' + error);
                    });
                    // 开始连接
                    //$.connection.hub.logging = true;
                    $.connection.hub.start({ transport: ['webSockets', 'serverSentEvents', 'longPolling'] }).done(function() {
                        //调用hub上的服务端方法
                        //连接Id
                        var cId = MyUtils.uuid.newUuid();
                        var url = g.parentCmp.orderCmp.requestHeadData.ScannerUrl + "&cId=" + cId + "&dcId=" + g.currentDocCateId;
                        window.open(url, "_self");
                        scanHub.server.startScan(cId);
                    });
                    */
                }
            }]
        });
    },
    setScanFiles:function (data) {
        console.log(data);
    }
});